<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <title>Detection Result</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            padding: 20px;
            background-color: black;
            background: url("/static/bg.png") no-repeat;
        }

        .content {
        }

        .output {
            display: flex;
            flex-wrap: wrap;
        }
        .output-panel {
            flex: 0 1 calc(50% - 20px); /* 每个板块占据一半宽度，减去间距 */
            margin: 10px;
            padding: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
            background-color: #f9f9f9;
            position: relative;
        }
        .output-panel h3 {
            margin-bottom: 15px;
        }
        .model-result {
            margin-bottom: 20px;
        }
        .final-result {
            margin-top: 20px;
            padding: 10px;
            border: 2px solid #000;
            border-radius: 5px;
            background-color: #ffeeba;
            font-size: 1.2em;
            font-weight: bold;
            text-align: center;
            position: absolute;
            bottom: 10px;
            left: 50%;
            transform: translateX(-50%);
        }
        canvas {
            width: 100%;
            height: auto;
        }


        nav a {
            margin-right: 15px;
            text-decoration: none;
            color: #007BFF;
        }
        nav a:hover {
            text-decoration: underline;
        }




        
        .tutorial-container {
            position: absolute;
            top: 15%;
            left: 5%;
            width: 90%;
            height: 80%;
            background-color: white;
            border-top-left-radius: 20px; /* 添加下方左边角的弧度 */
            border-top-right-radius: 20px; /* 添加下方右边角的弧度 */
            border-bottom-left-radius: 20px; /* 添加下方左边角的弧度 */
            border-bottom-right-radius: 20px; /* 添加下方右边角的弧度 */

        }
        
        .gradient-wave-background {
            position: relative;
            width: 100%;
            height: 100vh;
            overflow: hidden;
            opacity: 0;
            transform: translateY(20px);
            transition: opacity 1s ease-out, transform 1s ease-out;

            padding: 20px;

        }

        .gradient-wave-background::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-size: cover;
            opacity: 0.5;
        }

        .gradient-wave-background.show {
            opacity: 1;
            transform: translateY(0);
        }


        .tutorial_content_container {
            position: absolute;
        }





        

        /* 定义按钮的基础样式 */
        .smooth-button2 {
            position: relative;
            display: inline-block;
            padding: 10px 20px;
            font-size: 16px;
            color: #fff;
            background-color: rgba(0,123,255,0.7);
            border: none;
            border-radius: 5px;
            cursor: pointer;
            overflow: hidden;
            transition: background-color 0.3s ease;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
            animation: color-change 3s infinite, ripple-effect2 3s infinite;
        }

        /* 鼠标悬停时的样式 */
        .smooth-button2:hover {
            background-color: rgba(0,86,179,0.7);
            transform: translateY(-2px);
            box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
        }

        /* 定义颜色变化动画 */
        @keyframes color-change {
            0% {
                background-color: rgba(0,123,255,0.7);
            }
            50% {
                background-color: rgba(237, 211, 211, 0.7);
            }
            100% {
                background-color: rgba(0,123,255,0.7);
            }
        }

        /* 定义涟漪动画 */
        @keyframes ripple-effect2 {
            0% {
                box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.3), 0 0 0 10px rgba(0, 123, 255, 0.2);
            }
            50% {
                box-shadow: 0 0 0 20px rgba(255, 255, 255, 0), 0 0 0 30px rgba(0, 123, 255, 0);
            }
            100% {
                box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.3), 0 0 0 10px rgba(0, 123, 255, 0.2);
            }
        }



        .animated-text {
            display: inline-block;
            opacity: 0;
            animation: animated-text-fadeIn 1s forwards;
        }

        @keyframes animated-text-fadeIn {
            from {
                opacity: 0;
            }
            to {
                opacity: 1;
            }
        }


    </style>
</head>
<body>


    <div>
        <div class="content" id="content1", style="
            position: relative;
            top: 100px;
        ">
            <h1>
                <p, style="
                    color: wheat;
                ">Detection Result for {{ filename }}
                </p>
            </h1>

            {% if output %}
                <!-- <h2>Output:</h2>  -->
                <div class="output", style="
                    opacity: 0.8;
                ">
                    {% for op_name, result in output.items() %}
                        <div class="output-panel">
                            <h3>{{ op_name }}</h3>
                            <canvas id="chart-{{ op_name }}" width="400" height="200"></canvas>
                            <div class="model-results">
                                {% for model_result in result.model_results %}
                                    <div class="model-result">
                                        <h4>{{ model_result['model'] }}</h4>
                                        <p><strong>Check Result:</strong> {{ model_result['check result'] }}</p>
                                        <p><strong>Percent:</strong> {{ model_result['percent'] }}</p>
                                    </div>
                                {% endfor %}
                            </div>
                            <!-- <div class="final-result">
                                <strong>Final Result:</strong> {{ result.final_result }}
                            </div> -->
                        </div>
                    {% endfor %}
                </div>
            {% endif %}

            {% if error %}
                <h2>Error:</h2>
                <div class="error">
                    {% for op_name, err in error.items() %}
                        <div class="error-item">
                            <h3>{{ op_name }}</h3>
                            <pre>{{ err }}</pre>
                        </div>
                    {% endfor %}
                </div>
            {% endif %}
        </div>

        <div class="content" id="content2", style="
                background-color:rgb(243, 232, 213, 0.7);
                position: absolute;
                top: 200px;
                left: 55%;
                width: 45%;
                height: 150%;
                margin: 15px;
                border-radius: 2%;
            ">
            <h2 style="position: absolute; 
                        top: 5%; left: 50%; 
                        transform: translate(-50%, -50%); 
                        color: white;
            ">结果分析</h2>
            
            <div id="tutorial-container1" class="tutorial-container", style="
                position: relative;
                top: 10%;
            ">
                <div id = "gradient-wave-background1" class="gradient-wave-background", style="
                    position: absolute;
                    top: 5%;
                    left: 5%;
                    width: 90%;
                    height: 45%;
                    ">
                    <p id="summary-text"> </p>
                </div>
                
                <div id = "tutorial_content_container1" class = "tutorial_content_container", style="
                    position: absolute;
                    top: 55%;
                    left: 5%;
                    width: 90%;
                    height: 45%;
                    padding: 20px;
                    
                    ">



                    <button onclick="play_tutorials()" class="smooth-button2" style="
                        border-radius: 50%;
                        padding: 0; /* 去掉内边距 */
                        width: 60px; /* 设置按钮宽度 */
                        height: 60px; /* 设置按钮高度，保持正圆形 */
                        opacity: 0.6;
                        text-align: center;
                        z-index: 9999; /* 确保按钮显示在其他内容之上 */
                        background-color: lightblue;
                        cursor: pointer;
                        display: flex; /* 使用flex布局 */
                        align-items: center; /* 垂直居中 */
                        justify-content: center; /* 水平居中 */

                        position: absolute;
                        bottom: 10%;
                        left: 50%; 
                        transform: translate(-50%, -50%); 
                    ">
                        ▷|
                    </button>
                </div>
            </div>
        </div>
    </div>   

    <nav>
        <a href="{{ url_for('main') }}">Home</a>
    </nav>

    <script>

        const gradientWaveBackground = document.querySelector('.gradient-wave-background');

        document.addEventListener('DOMContentLoaded', function () {
            const summaryText = "{{ summary_text }}"; // 使用后端传递的数据
            const summaryTextElement = document.getElementById("summary-text");

            let delay = 0;
            for (const char of summaryText) {
                const span = document.createElement("span");
                span.textContent = char;
                span.style.animationDelay = `${delay}s`;
                span.classList.add("animated-text");
                summaryTextElement.appendChild(span);
                delay += 0.05; // 调整这个值来控制动画的速度
            }


            {% for op_name, result in output.items() %}
                var ctx = document.getElementById('chart-{{ op_name }}').getContext('2d');
                var percentValues = [];
                var labels = [];

                {% for model_result in result.model_results %}
                    percentValues.push(parseFloat('{{ model_result['percent'] }}'));
                    labels.push('{{ model_result['model'] }}');
                {% endfor %}

                var minValue = Math.min(...percentValues);
                var maxValue = Math.max(...percentValues);

                var chart = new Chart(ctx, {
                    type: 'bar',
                    data: {
                        labels: labels,
                        datasets: [{
                            label: 'Percent',
                            data: percentValues,
                            backgroundColor: '#36A2EB'
                        }]
                    },
                    options: {
                        scales: {
                            y: {
                                beginAtZero: true, // 确保从0开始
                                min: Math.min(0, minValue), // 动态调整最小值
                                max: Math.max(0, maxValue)  // 动态调整最大值
                            }
                        },
                        animation: {
                            duration: 1000, // 动画持续时间，单位为毫秒
                            easing: 'easeOutBounce' // 动画效果
                        }
                    }
                });
            {% endfor %}



            setTimeout(() => {
                    gradientWaveBackground.classList.add('show');
                }, 1000); // 假设content2的动画持续1秒
        });


        
    </script>
</body>


<script>
    // 监听滚动事件
    
    // 变量来跟踪content2的状态
    let content2Visible = false;
    let lastScrollPos = window.scrollY;




</script>
</html>
